package myjobs;

import java.util.Vector;
import java.util.Iterator;

/**
 * This class represents a match used by the MatchMakerJob.
 *
 * @author andreas
 */
public class Match {
    int maxPlayers;
    Vector<String> players = new Vector<String>();

    /**
     * Constructor takes the max number of players the match can have as parametre.
     *
     * @param maxPlayers the maximum number of players a match can have
     */
    public Match(int maxPlayers) {
        this.maxPlayers = maxPlayers;
    }

    /**
     * Use this method to get the player at a specified index.
     *
     * @param index the index of the player you want to get
     * @return The name of the player, null if no player or if the index is bigger than maxPlayers
     */
    public String getPlayerAt(int index) {
        if(index < maxPlayers) {
            return players.get(index);
        }
        return null;
    }

    /**
     * adds a player if the match isent full.
     *
     * @param player the name of the player to add
     */
    public void addPlayer(String player) {
        if(players.size() < maxPlayers) {
            players.add(player);
        }
    }

    /**
     * remove a player.
     *
     * @param player the name of the player to be removed
     */
    public void removePlayer(String player) {
        players.remove(player);
    }

    public int getMaxPlayers() {
        return maxPlayers;
    }

    public int getCurrentPlayers() {
        return players.size();
    }

    /**
     * Use this method to check if there is rome for more players.
     *
     * @return true if there is room for more, false if there isent.
     */
    public boolean roomForMorePlayers() {
        if(players.size() < maxPlayers) {
            return true;
        }
        else {
            return false;
        }
    }

    public boolean hasPlayer(String player) {
        return players.contains(player);
    }

    /**
     * Returns the iterator from the vector that contains all the players
     *
     * @return the iterator of players
     */
    public Iterator iterator() {
        return players.iterator();
    }
}
